using Web.Model;

namespace Web.DataAccess.Mappings
{
    public class CommentMapping : EntityMapping<Comment>
    {
        public CommentMapping()
        {
            References(x => x.Author);
            References(x => x.HeadComment);
            Map(x => x.DateCreated);
            Map(x => x.Text);
            HasManyToMany(x => x.Likes).Table("Likes").Cascade.SaveUpdate();
        }
    }

    public class HeadCommentMapping : EntityMapping<HeadComment>
    {
        public HeadCommentMapping()
        {
            References(x => x.Author);
            Map(x => x.DateCreated);
            Map(x => x.Text);
            HasManyToMany(x => x.Likes).Table("HeadLikes").Cascade.SaveUpdate();

            HasMany(x => x.ChildComments).Cascade.SaveUpdate().OrderBy("DateCreated DESC");
            ReferencesAny(x => x.Story)
                .EntityTypeColumn("StoryType")
                .EntityIdentifierColumn("StoryId")
                .IdentityType(x => x.Id)
                .MetaType<string>();
        }
    }
}